<template>
	<view class="main">
		<view class="active_tit">
			<view class="tit">
				股东构成情况
			</view>
			<!-- <view class="add" @click="add">
				＋
			</view> -->
		</view>
		<block v-for="(item,index) in stdOffsurShareholder" :key='index'>
			<view class="cut">股东{{index+1}} <uni-icons class="clear" type="clear" @click='stdDel(stdOffsurShareholder,item,"stdOffsurShareholder")'></uni-icons></view>
			<ActiveForm  ref='shName'>
				<view class="active_label">
					股东名称：
				</view>
				<view class="active_input">
					<input type="text"  v-model="item.shName" />
				</view>
			</ActiveForm>

			<ActiveForm  ref='sharesRatio'>
				<view class="active_label">
					持股比例（%）：
				</view>
				<view class="active_input">
					<input @input="ratio($event,item)"   v-model="item.sharesRatio" />
				</view>
			</ActiveForm>

			<ActiveForm  ref=''>
				<view class="active_label">
					备注：
				</view>
				<view class="active_input">
					<input type="text" v-model="item.exComments" />
				</view>
			</ActiveForm>
		</block>
		<view class="active_tit">
			<view class="" style="display: flex;">
				<view class="add" @click="add">
					新增股东
				</view>
			</view>
		</view>
		<!-- <button type="default" @click="getForm">getForm</button> -->
	</view>
</template>

<script>
	import SelectPicker from "../../SelectPicker";
	import RegionPicker from "../../RegionPicker";
	import region from '../areaList.js'
	export default {
		name: 'activeForm',
		data() {
			return {
				region,
				province: "",
				city: "",
				county: "",
				index: 1,
				stdOffsurShareholder: [],
				
			}
		},
		components: {
			SelectPicker,
			RegionPicker

		},
		watch: {
			stdOffsurShareholder: {
				handler: function(res) {
					//console.warn('stdOffsurShareholder组件数据变化', res)
					getApp().globalData.stdOffsurShareholder = res
				},
				deep: true
			}
		},
		mounted() {
			//获取返显数据
			setTimeout(()=>{
				//数据反显
				this.stdOffsurShareholder = getApp().globalData.stdOffsurShareholder
				if(getApp().globalData.isPad){
					this.getList()
				}
				
				
				
			},getApp().globalData.timeout)
			
		},
		methods: {
			ratio(e,item){
				console.log(e.detail.value)
				let val = e.detail.value
				if (val.length > 1 && val[0] == 0 && val[1] != '.') {
					//debugger
					val = Number(val) + ''
				}
				if (val[0] == '.') {
					val = ''
				}
				val = val.replace(/[^\d.]/g, "")
				val = val.replace(/[^\0-9\.]/g, '')
				val = val.replace(/\.{4,}/g, ".");
				val = val.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
				val = val.replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/, '$1$2.$3')
				setTimeout(()=>{
					item.sharesRatio = val
				},50)
			},
			getList(){
				this.sendRequest({
					url: 'loanBaseInfo/entShareHolder',
					method: 'post',
					hideLoading: true,
					data: {reqId:getApp().globalData.reqId},
					complete: (res) => {
						
						if (res.code == '200') {
							//判断是否已录入
							if(this.stdOffsurShareholder.length===0){
								for(let i=0;i<res.data.length;i++){
									
									var result = this.stdOffsurShareholder.some(item=>{
										if(item.shName==res.data[i].shareHolderName){
										    return true 
										} 
									})
									if(!result){
										let obj = {
											shName:res.data[i].shareHolderName,
											sharesRatio:Number(res.data[i].fundedRatio)*100,
											exComments:''
										}
										this.stdOffsurShareholder.push(obj)
									}
									
								}
								
							}
							
						   //this.stdOffsurShareholder = [...res.data,...this.stdOffsurShareholder]
						}
					}
				})
			},
			add() {
				let obj = {
					"businessId": "",
					"createTime": "",
					"createUser": "",
					"customerId": "",
					"customerSystemId": "",
					"deleteFlag": "",
					"entId": "",
					"entityRoleType": "",
					"exComments": "",
					"getDatTime": "",
					"imageUrl": "",
					"reqId": "",
					"shName": "",
					"sharesRatio": 0,
					"sourceSystem": "",
					"updateTime": "",
					"updateUser": "",
					"uuid": ""
				}
				this.stdOffsurShareholder.push(obj)
			}

		}
	}
</script>

<style lang="scss">


</style>
